import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout 引入最外层的相关组件 */
import Layout from '@/layout'
//常量路由
export const constantRoutes = [
  //登录
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  //404
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  //Layout
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },
]
//异步路由
export const asyncRouters = [
  //Product
  {
    path:'/product',
    component:Layout,
    name:'Product',
    meta:{title:'商品管理',icon:'el-icon-goods'},
    children: [
      {
        path:'tradeMark',
        name:'Trademark',
        component:()=>import('@/views/product/tradeMark/index'),
        meta:{title:'品牌管理'},
      },
      {
        path:'attr',
        name:'Attr',
        component:()=>import('@/views/product/attr/index'),
        meta:{title:'平台属性管理'},
      },
      {
        path:'spu',
        name:'Spu',
        component:()=>import('@/views/product/spu/index'),
        meta:{title:'SPU管理'},
      },
      {
        path:'sku',
        name:'Sku',
        component:()=>import('@/views/product/sku/index'),
        meta:{title:'SKU管理'},
      }
    ]
  },
  //权限管理
  {
    path:'/authority',
    component:Layout,
    name:'Acl',
    meta:{title:'权限管理',icon:'el-icon-lock'},
    children: [
      {
        path:'user',
        name:'User',
        component:()=>import('@/views/authority/user/index'),
        meta:{title:'用户管理'},
      },
      {
        path:'role',
        name:'Role',
        component:()=>import('@/views/authority/role/index'),
        meta:{title:'角色管理'},
      },
      {
        path:'menu',
        name:'Permission',
        component:()=>import('@/views/authority/menu/index'),
        meta:{title:'菜单管理'},
      },
    ]
  },
]
//任意路由
export const anyRouters = [
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]


const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
